#delimit;
clear all;
set more off;


import delimited "gallup_suffolk_clean.csv", encoding(ISO-8859-1);


gen year = substr(date, 1, 4);
destring year, replace;


*Restricting to Trump Admin;
drop if year == 2015 | year == 2016;
drop if date == "2017-01-04";
drop if date == "2021-02-03";



destring pair, ignore("NA") replace;
destring pres_approval_gallup_weighted, ignore("NA") replace;


replace pres_approval_gallup_weighted = pres_approval_weighted if org == "Gallup" & pres_approval_gallup_weighted == .;


gen pres_app_gallup_wt_pf = pres_approval_gallup_weighted*party_first;
gen pres_app_wt_pf = pres_approval_weighted*party_first;


*gen pres_app_gallup_pf = pres_approval_gallup*party_first;
label variable party_first "Party First";
label variable pres_approval_gallup_weighted "Gallup Pres. Approval";
label variable pres_approval_weighted "Pres. Approval";

label variable pres_app_gallup_wt_pf "Party First $\times$ Gallup Pres. Approval";

*gen pres_app_pf = pres_approval*party_first;
label variable pres_app_wt_pf "Party First $\times$ Pres. Approval";


*Full Sample Including Unmatched Gallup;
eststo: reg repub_weighted party_first , robust;
estadd local pair_FEs "No";

eststo: reg repub_weighted party_first pres_approval_gallup_weighted pres_app_gallup_wt_pf  , robust;
estadd local pair_FEs "No";

eststo: reg repub_weighted party_first pres_approval_weighted pres_app_wt_pf , robust;
estadd local pair_FEs "No";



*Restricting Sample to Matched Gallup and Including Pair Fixed Effects;

eststo: reg repub_weighted party_first i.pair, robust;
estadd local pair_FEs "Yes";

eststo: reg repub_weighted party_first pres_approval_gallup_weighted pres_app_gallup_wt_pf i.pair, robust;
estadd local pair_FEs "Yes";

eststo: reg repub_weighted party_first pres_approval_weighted pres_app_wt_pf i.pair, robust;
estadd local pair_FEs "Yes";


esttab using "Output/Gallup_Suffolk_Regs.tex", note("Two-sided p-values calculated from heteroskedasticity robust standard errors reported in parentheses")  
keep(party_first pres_approval_gallup_weighted pres_app_gallup_wt_pf pres_approval_weighted pres_app_wt_pf )
label p star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mlabels("" "" "" "" "" "" ) r2 scalars("pair_FEs Time Period Pair FEs")
title("Percentage of Respondents Identifying as Republican \label{GallupSuffolkRegs}") replace;
eststo clear;
